package com.settlement.system.controller;

import com.settlement.system.service.IBaseService;
import com.settlement.system.common.util.common.JsonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import com.settlement.system.model.entity.common.TblAkcFreightInsurance;
import jakarta.annotation.Resource;
import com.settlement.system.service.ITblAkcFreightInsuranceService;

import java.util.List;
import java.util.Map;

/**
 * 爱库存-运费无忧明细 前端控制器
 * @author Ximi
 * @since 2020-09-25
 */

@Api(tags = "爱库存-运费无忧明细",description = "爱库存-运费无忧明细")
@RestController
@RequestMapping("/akc/freight_insurance_detail")
public class TblAkcFreightInsuranceController extends MergeApiExcelController<TblAkcFreightInsurance, Map<String, Object>> {

    @Resource
    private ITblAkcFreightInsuranceService tblAkcFreightInsuranceService;

    @Override
    public IBaseService init() {
        return tblAkcFreightInsuranceService;
    }

    @Override
    public Class<?> getModelClass() {
        return TblAkcFreightInsurance.class;
    }

    @Override
    protected String verifyData(List<TblAkcFreightInsurance> list) {
        for (TblAkcFreightInsurance detail : list) {
            String message = verify(detail);
            if (!StringUtils.isEmpty(message)) {
                return message;
            }
        }
        return super.verifyData(list);
    }

    /**
     * 验证数据
     *
     * @param detail
     * @return
     */
    private String verify(TblAkcFreightInsurance detail) {
        if (StringUtils.isEmpty(detail.getActionName()) &&
                StringUtils.isEmpty(detail.getAkcVerifyBillType()) &&
                StringUtils.isEmpty(detail.getBusinessName()) &&
                StringUtils.isEmpty(detail.getBusinessNumber())&&
                StringUtils.isEmpty(detail.getVerifyBillNo())&&
                StringUtils.isEmpty(detail.getActionId())&&
                StringUtils.isEmpty(detail.getSecondOrderNo())) {
            return JsonUtil.getJsonOrToString(detail) + ":活动名称,对账单号,活动编号,对账单类型,商家名称，商家编号,二级订单编号不能同时为空";
        }
        return null;
    }

}

